home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 131 / XENIATGM131.iso / Shareware / openOffice.org 641 / Windows / f_0266 / Common.xba < prev    next >
Extensible Markup Language  |  2001-11-19  |  8KB  |  256 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
  3. <script:module xmlns:script="http://openoffice.org/2000/script" script:name="Common" script:language="StarBasic"> REM  *****  BASIC  *****
  4. Public DialogModel as Object
  5. Public DialogConvert as Object
  6. Public DialogPassword as Object
  7. Public PasswordModel as Object
  8.  
  9. Sub    RetrieveDocumentObjects()
  10.     CurMimeType = GetDocumentType(oDocument)
  11.     If Instr(1, CurMimeType, "calc") <> 0 Then
  12.         oSheets = oDocument.Sheets
  13.         oSheet = oDocument.Sheets.GetbyIndex(0)
  14.         oAddressRanges = oDocument.createInstance("com.sun.star.sheet.SheetCellRanges")
  15.     End If
  16.     ' Retrieve the indices for the cellformatations
  17.     oFormats = oDocument.NumberFormats
  18. End Sub
  19.  
  20.  
  21. Sub CancelTask()
  22. '    If Not DocDisposed Then
  23. '        ReprotectSheets()
  24. '    End If
  25.     If DialogModel.Step = 3 And (Not bCancelTask) Then
  26.         If Msgbox(sMsgCancelConversion, 36, sMsgCancelTitle) = 6 Then
  27.             bCancelTask = True
  28.             DialogConvert.EndExecute
  29.         Else
  30.             bCancelTask = False
  31.         End If
  32.     Else
  33.         DialogConvert.EndExecute()
  34.     End If
  35. End Sub
  36.  
  37.  
  38. Function ConvertDocument()
  39.     GoOn = True
  40. '    DocDisposed = True
  41.     InitializeProgressbar()
  42.     If Instr(1, CurMimeType, "calc") <> 0 Then
  43.         bDocHasProtectedSheets = CheckSheetProtection(oSheets)
  44.         If bDocHasProtectedSheets Then
  45.             bDocHasProtectedSheets = UnprotectSheetsWithPassword(oSheets, bDoUnProtect)
  46.         End If
  47.         If Not bDocHasProtectedSheets Then
  48.             If Not bRangeListDefined Then
  49.                 TotCellCount = 0
  50.                 CreateRangeEnumeration(True)
  51.             Else
  52.                 IncreaseStatusvalue(SBRelGet/3)
  53.             End If
  54.             RangeIndex = Ubound(RangeList(), 1)
  55.             If RangeIndex > -1 Then
  56.                 ConvertThehardWay(RangeList(), True, False)
  57.                 MakeStyleEnumeration(True)
  58.                 oDocument.calculateAll()
  59.             End If
  60.             ReprotectSheets()
  61.             bRangeListDefined = False
  62.         End If
  63.     Else
  64.         oStatusline.SetValue(10)
  65.         ConvertTextFields()
  66.         oStatusline.SetValue(80)
  67.         ConvertWriterTables()
  68.     End If
  69.     oStatusline.End
  70.     On Local Error Goto 0
  71. End Function
  72.  
  73.  
  74. Sub SwitchNumberFormat(oObject as Object, oFormats as object)
  75. Dim nFormatLanguage as Integer
  76. Dim nFormatDecimals as Integer
  77. Dim nFormatLeading as Integer
  78. Dim bFormatLeading as Integer
  79. Dim bFormatNegRed as Integer
  80. Dim bFormatThousands as Integer
  81. Dim i as Integer
  82. Dim aNewStr as String
  83. Dim iNumberFormat as Long
  84. Dim AddToList as Boolean
  85. Dim sOldCurrSymbol as String
  86.     On Local Error Resume Next
  87.     iNumberFormat = oObject.NumberFormat
  88.     On Local Error GoTo NOKEY
  89.     aFormat() = oFormats.getByKey(iNumberFormat)
  90.     On Local Error GoTo 0
  91.     sOldCurrSymbol = aFormat.CurrencySymbol
  92.     If sOldCurrSymbol = CurrValue(CurrIndex,5) Then
  93.         aSimpleStr = "0 [$EUR]"
  94.     Else
  95.         aSimpleStr = "0 [$" & sEuroSign & aFormat.CurrencyExtension & "]"
  96.     End If
  97.  
  98.     ' Numberformat mit dem neuen Symbol als Basis f├╝r generateFormat
  99.     nSimpleKey = Numberformat(oFormats, aSimpleStr, oLocale)
  100.     ' Typ und W├ñhrungssymbol des Numberformats heraussuchen
  101.     ' neues W├ñhrungsformat mit passenden Einstellungen setzen
  102.     nFormatDecimals = 2
  103.     nFormatLeading = aFormat.LeadingZeros
  104.     bFormatNegRed = aFormat.NegativeRed
  105.     bFormatThousands = aFormat.ThousandsSeparator
  106.     aNewStr = oFormats.generateFormat( nSimpleKey, aFormat.Locale, bFormatThousands, bFormatNegRed, nFormatDecimals, nFormatLeading)
  107.     oObject.NumberFormat = Numberformat(oFormats, aNewStr, aFormat.Locale)
  108.     NOKEY:
  109.     If Err <> 0 Then
  110.         Resume CLERROR
  111.     End If
  112.     CLERROR:
  113. End Sub
  114.  
  115.  
  116. Function Numberformat( oFormats as Object, aFormatStr as String, oLocale as Object)
  117. Dim nRetkey 
  118. Dim l as String
  119. Dim c as String
  120.     nRetKey = oFormats.queryKey( aFormatStr, oLocale, True )
  121.     If nRetKey = -1 Then
  122.         l = oLocale.Language
  123.         c = oLocale.Country
  124.         nRetKey = oFormats.addNew( aFormatStr, oLocale )
  125.         If nRetKey = -1 Then nRetKey = 0
  126.     End If
  127.     Numberformat = nRetKey
  128. End Function
  129.  
  130.  
  131. ' Funktion findet den Formattyp einer Vorlage, Zelle oder eines Bereiches heraus und schreibt das Ergebnis
  132. ' in die globale Variable nFormatType; Ist ein W├â┬ñhrungssymbol gesetzt, wird dieses in den globalen String
  133. ' sFormatCurrency geschrieben.
  134. Function CheckFormatType( FormatObject as object)
  135. Dim i as Integer
  136. Dim LocCurrIndex as Integer
  137. Dim nFormatFormatString as String
  138. Dim FormatLangID as Integer
  139. Dim sFormatCurrExt as String
  140. Dim oFormatofObject() as Object
  141.  
  142.     ' Retrieve the Format of the Object
  143.     On Local Error GoTo NOKEY
  144.     oFormatofObject = oFormats.getByKey(FormatObject.NumberFormat)
  145.     On Local Error GoTo 0            
  146.     ' Typ und W├ñhrungssymbol des Numberformats heraussuchen
  147.       If NOT INT(oFormatofObject.Type) AND com.sun.star.util.NumberFormat.CURRENCY Then
  148.         CheckFormatType = False
  149.         Exit Function
  150.     End If
  151.     If FieldinArray(CurrSymbolList(),2,oFormatofObject.CurrencySymbol) Then
  152.         ' If the Currencysymbol of the object ist the one needed, then check the Currency extension
  153.         sFormatCurrExt = oFormatofObject.CurrencyExtension
  154.  
  155.         If FieldInList(CurExtension(),2,sFormatCurrExt) Then
  156.             ' The Currency - extension also fits
  157.             CheckFormatType = True
  158.         Else
  159.             ' The Currency - symbol is Euro-conforming (like 'DEM'), so there is no Currency-Extension
  160.             CheckFormatType = oFormatofObject.CurrencySymbol = CurrsymbolList(2)
  161.         End If
  162.     Else
  163.         ' The Currency Symbol of the object is not the desired one
  164.         If oFormatofObject.CurrencySymbol = "" Then
  165.             ' Format is "automatic"
  166.             CheckFormatType = CheckLocale(oFormatofObject.Locale)
  167.         Else
  168.             CheckFormatType = False
  169.         End If
  170.     End If
  171.  
  172.     NOKEY:
  173.     If Err <> 0 Then
  174.         CheckFormatType = False
  175.         Resume CLERROR
  176.     End If
  177.     CLERROR:
  178. End Function
  179.  
  180.  
  181. Sub StartConversion()
  182.     GoOn = True
  183.     Select Case DialogModel.Step
  184.         Case 1
  185.             If DialogModel.chkComplete.State = 1 Then
  186.                 ConvertWholeDocument()
  187.             Else
  188.                 ConvertRangesorStylesofDocument()
  189.             End If
  190.         Case 2
  191.             bCancelTask = False
  192.             InitializeThirdStep()
  193.             ConvertDocuments()
  194.             bCancelTask = True
  195.         Case 3
  196.             DialogConvert.EndExecute()
  197.     End Select
  198. End Sub
  199.  
  200.  
  201. Sub IncreaseStatusValue(AddStatusValue as Integer)
  202.     StatusValue = Int(StatusValue + AddStatusValue)
  203.     oStatusline.SetValue(StatusValue)
  204. End Sub
  205.  
  206.  
  207. Sub SelectCurrency()
  208. Dim AddtoList as Boolean
  209. Dim UpRangeList as Integer
  210. Dim OldCurrIndex as Integer
  211.     bRangeListDefined = False
  212.     OldCurrIndex = CurrIndex
  213.     CurrIndex = DialogModel.lstCurrencies.SelectedItems(0)
  214.     InitializeCurrencyValues(CurrIndex)
  215.     CurExtension(0) = LangIDValue(CurrIndex,0,2)
  216.     CurExtension(1) = LangIDValue(CurrIndex,1,2)
  217.     CurExtension(2) = LangIDValue(CurrIndex,2,2)
  218.     If DialogModel.Step = 1 Then
  219.         EnableStep1DialogControls(False,False, False)
  220.         If DialogModel.optCellTemplates.State = 1 Then
  221.             EnableStep1DialogControls(False, False, False)
  222.             CreateStyleEnumeration()
  223.         ElseIf ((DialogModel.optSheetRanges.State = 1) OR (DialogModel.optDocRanges.State = 1)) AND (DialogModel.Step = 1) Then
  224.             UpRangeList = UBound(RangeList())
  225.             ReDim RangeList(UpRangeList) 'as String
  226.             CreateRangeEnumeration(False)
  227.         ElseIf DialogModel.optSelRange.State= 1 Then
  228.             'Preselected Range
  229.         End If
  230.         EnableStep1DialogControls(True, True, True)
  231.     ElseIf DialogModel.Step = 2 Then
  232.         EnableStep2DialogControls(True)
  233.     End If
  234. End Sub
  235.  
  236.  
  237. Sub FillUpCurrencyListbox()
  238. Dim i as Integer
  239. Dim MaxIndex as Integer
  240.     MaxIndex = Ubound(CurrValue(),1)
  241.     Dim LocList(MaxIndex) as String
  242.     For i = 0 To MaxIndex
  243.         LocList(i) = CurrValue(i,0)
  244.     Next i
  245.     DialogModel.lstCurrencies.StringItemList() = LocList()
  246.     If CurrIndex > -1 Then
  247.         SelectListboxItem(DialogModel.lstCurrencies, CurrIndex)
  248.     End If
  249. End Sub
  250.  
  251.  
  252. Sub InitializeProgressbar()
  253.     CurCellCount = 0
  254.     oStatusline.Start(sStsPROGRESS,100)             '"Konvertierungsfortschritt:"
  255.     StatusValue = 0
  256. End Sub</script:module>